<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>资料审核</title>
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
</head>
<style>
    #refuse:hover{
        cursor: pointer;
    }
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div id="searchForm" style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">资料名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="resourceName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="search"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-sm" lay-event="lookInfo">查看资料</a>
            <a id="pass" lay-event="pass" class="layui-btn layui-btn-normal layui-btn-sm">审核通过</a>
            <a id="auditRefuse" lay-event="auditRefuse" class="layui-btn layui-btn-danger layui-btn-sm">审核拒绝</a>
        </script>
        <script type="text/html" id="auditState">
            {{# if(d.auditState===0){}}
            <span style="color: black">待审核</span>
            {{#}else if(d.auditState===1){}}
            <span style="color: green">已通过</span>
            {{#}else if(d.auditState===2){ }}
            <span id="refuse" lay-event="refuse" style="color: red">已拒绝</span>
            {{#}else if(d.auditState===3){ }}
            <span style="color: red">已过期</span>
            {{#}}}
        </script>
    </div>
</div>
<script th:inline="none">
    let myTable;
    layui.use(['form', 'table'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        myTable = table.render({
            elem: '#currentTableId',
            url: '/resourceAudit/pageList',
            method: "get",
            toolbar: '#toolbarDemo',
            parseData: function (res) {
                return {
                    "code": 0,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.list
                }
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'auditId', width: "8%", title: '审核编号', sort: true, align: "center"},
                {field: 'resourceId', width: "10%", title: '资料ID', hide: true, align: "center"},
                {field: 'resourceName', width: "26%", title: '资料名称', align: "center"},
                {field: 'publisherId', width: "10%", title: '发布人ID', hide: true, align: "center"},
                {field: 'publisher', width: "10%", title: '发布人', align: "center"},
                {field: 'reviewer', width: "10%", title: '审核人', align: "center"},
                {field: 'auditTime',width:"14%",title: '审核时间', align: "center"},
                {field: 'auditState', title: '审核状态', width: "9%", templet: '#auditState',sort:true, align: "center"},
                {field: 'publishState', title: '操作', toolbar: '#currentTableBar', align: "center"}
            ]],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                , curr: 1 //设定初始在第 1 页
                , limit: 10
                , limits: [10, 15, 30, 60]
                , groups: 5 //只显示 1 个连续页码
            },
            request: {
                pageName: "pageNum",
                limitName: "pageSize"
            },
            done:function (){
                $("table").css("width","100%");
            }
        });

        //搜索
        form.on('submit(search)', function(data){
            console.log("搜索");
            myTable.reload({
                url:"/resourceAudit/searchAudit",
                method: "post",
                page: {
                    curr: 1 //设定初始在第 5 页
                    ,limit: 10
                },
                request:{
                    pageName:"pageNum",
                    limitName: "pageSize"
                },
                where:{
                    resourceName:data.field.resourceName,
                },
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            if (obj.event === 'lookInfo') {
                let layer = layui.layer;
                $.ajax({
                    type: "post",
                    url: '/resource/queryFileUrl',
                    data: {resourceId: data.resourceId},
                    success: function (res) {
                        layer.open({
                            type: 2,
                            area: ['100%', '100%'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: '/upload/'+res.data.url
                        });
                        return false;
                    }
                })
                return false;
            }else if(obj.event==='refuse'){
                $.ajax({
                    type: "post",
                    url: '/resourceAudit/refuseCause',
                    data: {resourceId: data.resourceId},
                    success: function (res) {
                        layer.alert(res.message);
                    }
                })
            }else if(obj.event==='pass'){
                if(data.auditState!==0){
                    layer.msg("此资料不能进行审核", {time: 5000, icon: 1, offset: [15]});
                    return false;
                }
                let index = layer.open({
                    title: '审核通过',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['650px', '400px'],
                    content: "/auditCause/goToPassAudit?auditType='resourceAudit'&auditId="+data.resourceId
                });
            }else if(obj.event==='auditRefuse'){
                if(data.auditState!==0){
                    layer.msg("此资料不能进行审核", {time: 5000, icon: 1, offset: [15]});
                    return false;
                }
                let index = layer.open({
                    title: '审核拒绝',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['650px', '400px'],
                    content: "/auditCause/goToRefuseAudit?auditType='resourceAudit'&auditId="+data.resourceId
                });
            }
        });
    });
</script>
</body>
</html>